import java.util.Iterator;
import java.util.Scanner;



public class MemInfoMain {
	private static final String MENU = "0)종료 1)삽입 2)조회 3)수정 4)삭제 ";
	private static final String ERRMSG = "잘못된 코드를 입력하셨습니다.";
	private static final String EXITOK = "프로그램을 종료합니다!";
	private static final String DELMSG1 = "삭제할 회원 아이디를 입력하세요.";
	private static final String DELOK = "성공적으로 회원정보가 삭제되었어요!";
	private static Scanner sc = new Scanner(System.in);
	private static MemInfoDAO srv = new MemInfoDAO();
	
	public static void main(String[] args) {
		while(true){
			System.out.print(MENU);
			switch(sc.next()){
				case "0": 
					exitMember();
					break;
				case "1":
					addMember();
					break;
				case "2":
					readMember();
					break;
				case "3":
					modifyMember();
					break;
				case "4":
					deleteMember();
					break;
				default :
					System.out.println(ERRMSG);
			}
		}
	}

	private static void deleteMember() {
		readMember();
		String userid;
		System.out.println(DELMSG1);
		userid = sc.next();
		if(srv.deleteMem(userid)>0)
			System.out.println(DELOK);
	}

	private static void modifyMember() {
		readMember();
		MemInfoVO mv = new MemInfoVO();
		System.out.println("수정할 id 입력");
		mv.setUid(sc.next());
		System.out.println("수정할 이름,번호 입력");
		mv.setUname(sc.next());
		mv.setPhone(sc.next());
		if(srv.updateMem(mv)>0){
			System.out.println("성공했습니다.");
		}
	}

	private static void readMember() {
		Iterator<MemInfoVO> it = srv.selectMem().iterator();
		while(it.hasNext()){
			System.out.println(it.next());
		}
	}

	private static void addMember() {
		System.out.println("이름, 성, 주소, 전화번호 순으로 입력");
		MemInfoVO mv = new MemInfoVO(sc.next(), sc.next(), sc.next(), sc.next());
		if(srv.insertMem(mv)>0)
			System.out.println("성공했습니다.");
	}

	private static void exitMember() {
		sc.close(); 
		System.out.println(EXITOK);
		System.exit(0);
	}

}
